//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.cn.core.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class SerializationUtils {
    public SerializationUtils() {
    }

    public static <T extends Serializable> T clone(final T object) {
        if (object == null) {
            return null;
        } else {
            byte[] objectData = serialize(object);
            return (T) deserialize(objectData);
        }
    }

    public static byte[] serialize(Object object) {
        if (object == null) {
            return null;
        } else {
            ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);

            try {
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                Throwable var3 = null;

                try {
                    oos.writeObject(object);
                    oos.flush();
                } catch (Throwable var13) {
                    var3 = var13;
                    throw var13;
                } finally {
                    if (var3 != null) {
                        try {
                            oos.close();
                        } catch (Throwable var12) {
                            var3.addSuppressed(var12);
                        }
                    } else {
                        oos.close();
                    }

                }
            } catch (IOException var15) {
                IOException ex = var15;
                throw new IllegalArgumentException("Failed to serialize object of type: " + object.getClass(), ex);
            }

            return baos.toByteArray();
        }
    }

    public static Object deserialize(byte[] bytes) {
        if (bytes == null) {
            return null;
        } else {
            try {
                ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
                Throwable var2 = null;

                Object var3;
                try {
                    var3 = ois.readObject();
                } catch (Throwable var14) {
                    var2 = var14;
                    throw var14;
                } finally {
                    if (var2 != null) {
                        try {
                            ois.close();
                        } catch (Throwable var13) {
                            var2.addSuppressed(var13);
                        }
                    } else {
                        ois.close();
                    }

                }

                return var3;
            } catch (IOException var16) {
                throw new IllegalArgumentException("Failed to deserialize object", var16);
            } catch (ClassNotFoundException var17) {
                throw new IllegalStateException("Failed to deserialize object type", var17);
            }
        }
    }
}
